What are Laravel | CSRF Protection?

Report
Question
719 views

Cross-Site Request Forgery (CSRF) is a type of attack that performed by the attacker to send requests to a system with the help of an authorized user who is trusted by the system.

Please explain why do you think this question should be reported?

Report Cancel

How to Use: This CSRF token protection can be applied to any HTML form in Laravel application by specifying a hidden form field of CSRF token. The requests are validated automatically by the CSRF VerifyCsrfToken middleware.

There are three different ways in which you can do this.

  1. @csrf
  2. csrf_field()
  3. csrf_token()

@csrf: This is a blade template directive for generating the hidden input field in the HTML form.

<!DOCTYPE html>
<html>
    <head>
        <title>Laravel | CSRF Protection</title>
    </head>
    <body>
        <section>
            <h1>CSRF Protected HTML Form</h1>
            <form method="POST">
                @csrf
                
                <input type="text" name="username"
                                            placeholder="Username">
                <input type="password" name="password"
                                            placeholder="Password">
                <input type="submit" name="submit" value="Submit">
            </form>
        </section>
    </body>
</html>

Thread Reply

  1.  Neel
    Full Stack Developer 0 Votes
    2 years ago

    Please briefly explain why you feel this answer should be reported .

    Report Cancel
    Bbigufyfuchchchchvhvhchchc

Leave an comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>